source pdb.tcl
proc save {fname str} {
    set f [open $fname w]
    puts $f $str
    close $f
}


#1a30 have 3 chains and is X-ray structure. Its terminus is OXT
set pdbid 1a30
#1d7n is NMR structure and has only one chain. Its terminus is NH2
#set pdbid 1d7n 
# 1zy6 has SSbonds
set pdbid 1zy6
PDB create $pdbid
$pdbid fetch $pdbid
# change NH2 from hetatom to atom
$pdbid het2atom
$pdbid process
puts "$pdbid" 
puts "Has [$pdbid hasNmodel] model"
if { [$pdbid hasNmodel] > 1 } {
    puts "This is a NMR structure"
    set firstModel 1
} else {
    puts "THis is a X-Ray structure"
    # X-Ray structure has its first model index set as 0 instead
    set firstModel 0
}
foreach ssbond [$pdbid ssbonds] {
    puts "has ssbound: $ssbond"
}
foreach chain [$pdbid chains] {
    #get charmm readable pdb file
    # use getCoor instead for original pdb format
    puts "Chain $chain: [$pdbid chainlen $chain]"
    puts [$pdbid sequence $chain]
    puts "Saving chain $chain into file ${pdbid}_$chain.pdb"
    save ${pdbid}_$chain.pdb [$pdbid getCharmm $firstModel $chain]
}
